home *** CD-ROM | disk | FTP | other *** search
- /*
-
- GetEOF XCMD v1.2
-
- ©1990-1 Apple Computer, Inc.; by Mike Byrne
-
- This XCMD takes a full pathname, converts it to a volume reference and a partial pathname,
- opens the file, reads the EOF number, closes the file, and returns the EOF.
-
- Form:
- GetEOF(<full pathname>)
-
- # the MPW 3.2 build commands:
- C -b GetEOF.c -mbg off
- Link -w -t STAK -c WILD -rt XFCN=602 ∂
- -m ENTRYPOINT ∂
- -sg GetEOF ∂
- GetEOF.c.o ∂
- "{Libraries}HyperXLib.o" ∂
- "{Libraries}Runtime.o" ∂
- "{Libraries}Interface.o" ∂
- "{CLibraries}StdCLib.o" ∂
- -o "some stack"
- */
-
- #include <Types.h>
- #include <string.h>
- #include <Memory.h>
- #include <Files.h>
- #include <Packages.h>
- #include "HyperXCmd.h"
-
- #define NULL 0L
- #define NIL 0L
-
- #define kNumParams 1
-
- /* prototypes */
- void ErrorBack(XCmdPtr paramPtr, char *message);
- void MoveLockParams ( XCmdPtr paramPtr, short paramCount );
- void UnlockParams ( XCmdPtr paramPtr, short paramCount );
-
-
- pascal void EntryPoint(XCmdPtr paramPtr)
- {
- short i,j, refNum;
- long theEOF = 0;
- char volName[34];
- char ppathName[301];
- short vRefNum;
-
-
- /* move high and lock the parameters. */
- MoveLockParams(paramPtr, paramPtr->paramCount);
-
- /* check for copyright or syntax help request */
- if (!strcmp( (char*)*paramPtr->params[0], "!") ) {
- ErrorBack(paramPtr, "v1.2, ©1990-1 Apple Computer, Inc.; by Mike Byrne");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- } else if (!strcmp ( (char*)*paramPtr->params[0], "?") ) {
- ErrorBack(paramPtr, "GetEOF syntax is 'GetEOF(<full pathname>)'");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- }
-
- /* not a copyright or help request. */
- /* check for correct number of parameters */
- if (paramPtr->paramCount != kNumParams) {
- ErrorBack(paramPtr, "Error: GetEOF syntax is 'GetEOF(<full pathname>)'");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- }
-
- /* move high and lock the parameters... */
- MoveLockParams(paramPtr, kNumParams);
-
- /* extract the volume name from the handle, copy to a pas string,
- and get the volume reference number of the volume */
- for (i=0; ((*(paramPtr->params[0]))[i] != ':' && (i < 33)); i++)
- { volName[i] = (*(paramPtr->params[0]))[i]; }
- volName[i] = ':';
- volName[i+1] = '\0';
- c2pstr(volName);
- vRefNum = 0;
-
- if (SetVol(volName, vRefNum) != noErr) { // toolbox
- ErrorBack(paramPtr, "Error: Could not set the default volume");
- UnlockParams(paramPtr, kNumParams);
- return;
- }
-
- if (GetVol(&volName, &vRefNum) != noErr) { // toolbox
- ErrorBack(paramPtr, "Error: Could not find the volume requested.");
- UnlockParams(paramPtr, kNumParams);
- return;
- }
-
- /* now, copy the rest of the pathname to the partial pathname and convert it. */
- for (j=i; (j <= strlen((*(paramPtr->params[0]))) && (j < 300)); j++)
- { ppathName[j-i] = (*(paramPtr->params[0]))[j]; }
- c2pstr(ppathName);
-
- /* open the file */
- if ( FSOpen(ppathName, vRefNum, &refNum) != noErr) { // toolbox
- ErrorBack(paramPtr, "Error: Cannot open file.");
- UnlockParams(paramPtr, kNumParams);
- return;
- }
-
- /* now, get the eof (use j for the logEOF) */
- if ( GetEOF(refNum, &theEOF) != noErr) { // toolbox
- ErrorBack(paramPtr, "Error: Cannot find end-of-file.");
- UnlockParams(paramPtr, kNumParams);
- return;
- }
-
- /* now, close the file */
- FSClose(refNum); // toolbox
-
- /* now, convert the number to a string and send it back. */
- NumToStr(paramPtr, theEOF, &ppathName);
- p2cstr(ppathName);
- ErrorBack(paramPtr, ppathName);
- UnlockParams(paramPtr, kNumParams);
- return;
- }
-
-
-
-
-
-
- /* allocate and load up paramPtr->returnValue with a string
- -------------------------------------------------------- */
- void ErrorBack(XCmdPtr paramPtr, char *message)
- {
- Handle mesHnd;
-
- /*
- Allocate space for an error message.
- Copy the string into it.
- Return the handle to HyperCard.
- */
- mesHnd = NewHandle((long)(strlen(message)+1)); /* toolbox */
- if (mesHnd == nil) return;
- strcpy((char *)*mesHnd,message);
- paramPtr->returnValue = mesHnd;
- }
-
-
-
- /* move high and lock down all parameters (watch that these are read-only)
- ----------------------------------------------------------------------- */
- void MoveLockParams ( XCmdPtr paramPtr, short paramCount )
- {
- short i;
-
- for(i=0; i <= paramCount-1; i++)
- {
- MoveHHi(paramPtr->params[i]); /* toolbox */
- HLock(paramPtr->params[i]); /* toolbox */
- }
- }
-
-
-
-
- /* unlock all parameter handles in the XCmdBlock
- --------------------------------------------- */
- void UnlockParams ( XCmdPtr paramPtr, short paramCount )
- { short i;
-
- for(i=0; i <= paramCount-1; i++)
- { HUnlock(paramPtr->params[i]);} /* toolbox */
- }
-